import { Component, ViewChild, AfterViewInit } from '@angular/core';
import {DataSource} from '@angular/cdk/collections';
import {HttpClient} from '@angular/common/http';
import {BehaviorSubject,Observable} from 'rxjs';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
import {MatTable} from '@angular/material/table';
import {MatTableDataSource} from '@angular/material/table';
import {MatPaginator} from '@angular/material/paginator'

@Component({
  selector: 'app-staff',
  templateUrl: './staff.component.html',
  styleUrls: ['./staff.component.css']
})
export class StaffComponent implements AfterViewInit {

  constructor(public http:HttpClient,private route:ActivatedRoute,private router:Router) { }

  displayedColumns: string[] = ['staffId','staffName','staffAge','staffGender','staffInTime','operations'];
  dataSource=new MatTableDataSource<StaffElement>(ELEMENT_DATA);
  @ViewChild(MatPaginator) paginator:MatPaginator;

  ngAfterViewInit() {
    let api='https://localhost:44312/api/staff'
    this.http.get(api).subscribe((res:any)=>{
      console.log(res);
      ELEMENT_DATA=res;
      this.dataSource=new MatTableDataSource<StaffElement>(ELEMENT_DATA);
      this.dataSource.paginator=this.paginator;
    })
  }
  Btn_Edit(staffid){
    console.log(staffid);
    
    localStorage["staffid"]=staffid;
    console.log(localStorage["staffid"]);
    this.router.navigate(['/staff-addor-edit-component'])
  }
  Btn_Delete(staffid){
    console.log(staffid);
    let api='https://localhost:44312/api/staff/'+staffid
    this.http.delete(api).subscribe((res:any)=>{
      console.log(res);
      if(res.state=1){
        
      }
    })
  }
}
export interface StaffElement{
  staffId:number;
  staffName:string;
  staffAge:number;
  staffGender:boolean;
  staffInTime:Date;
}
var ELEMENT_DATA:StaffElement[]=[];